package sunwin.yoms.web.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import sunwin.yoms.comm.YomsException;
import sunwin.yoms.comm.YomsFunction;
import sunwin.yoms.domain.system.SysWebDomain;
import sunwin.yoms.service.system.SysWebService;
import sunwin.yoms.web.comm.R;
import sunwin.yoms.web.comm.YomsAjaxAnswer;
import sunwin.yoms.web.comm.YomsController;

/**
 * Created by watson on 2015/9/8.
 */
@Controller
public class SysWebController {
    @Autowired
    private SysWebService sysWebService;

    public final String EditWvm = "system/sysweb.edit";
    public final String CommentVm = "system/comment";

    /**
     * 访问编辑页面
     */
    @RequestMapping(value = R.EditSysweb, method = RequestMethod.GET)
    @YomsController(functionNo = YomsFunction.EidtSysweb, viewName = EditWvm)
    public ModelAndView editSysWeb(@RequestParam(required = false, defaultValue = "1") int id) throws YomsException {
        SysWebDomain sysWebDomain = sysWebService.getConfig();
        ModelAndView mav = new ModelAndView();
        mav.addObject("SysWeb", sysWebDomain);
        return mav;

    }

    /**
     * 编辑首页配置
     */
    @RequestMapping(value = R.EditSysweb, method = RequestMethod.POST)
    @YomsController(functionNo = YomsFunction.EidtSysweb, viewName = EditWvm)
    @ResponseBody
    public YomsAjaxAnswer editSysWeb(SysWebDomain sysWebDomain) throws YomsException {
        sysWebService.upSysWeb(sysWebDomain);
        YomsAjaxAnswer yomsAjaxAnswer = new YomsAjaxAnswer();
        yomsAjaxAnswer.setSuccess(true);
        return yomsAjaxAnswer;
    }

    @RequestMapping(value = R.Comment, method = RequestMethod.GET)
    @YomsController(functionNo = YomsFunction.Comment, viewName = CommentVm)
    public void comment() {

    }
}
